package com.hongning.railway.ui.main.fragments.college;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.resbean.Fileterbean;
import com.hongning.railway.ui.main.mine.partymember.itemviewmodel.PartyQuestionItemNameViewModel;
import com.hongning.railway.ui.uichangeobserable.DialogUIChangeObserable;

import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;

public class CollegeFilterViewModel extends BaseViewModel<AppRepository> {
    public ObservableList<List<Fileterbean>> viewlist = new ObservableArrayList<>();
    public DialogUIChangeObserable dialogUIChangeObserable = new DialogUIChangeObserable();
    public CollegeFilterViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }

    /**
     * 初始化数据
     */
    public void init(){
        model.getTypesForApp()
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog();
                    }
                }).doOnTerminate(new Action() {
            @Override
            public void run() throws Exception {
                dismissDialog();
            }
        }).subscribe(new ApiDisposableObserver<List<Fileterbean>>() {
            @Override
            public void onResult(List<Fileterbean> fileterbeans) {
                viewlist.add(fileterbeans);
                dialogUIChangeObserable.fileterBeans.setValue(fileterbeans);

            }
        });
    }
}
